package com.example.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {


    //字符串转时间
    public static Date getDateByString(String time, String style){
        SimpleDateFormat dateFormat = new SimpleDateFormat(style);

        Date date = null;
        try {
            date = dateFormat.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    //时间转字符串
    public static String getStringByDate(Date date, String style){
        SimpleDateFormat dateFormat = new SimpleDateFormat(style);
        String time = null;
        time = dateFormat.format(date);
        return time;
    }

    //长的时间戳转时间
    public static Date getDateByTimestamp(Long timestamp, String style){
        SimpleDateFormat dateFormat = new SimpleDateFormat(style);

        Date date = new Date(timestamp);
        return date;

    }

    //短的时间戳转时间
    //2021-07-29T00:00:00.000Z 转 时间

    //日期相减
    //日期相加
}
